package com.xbongbong.paas.enums;

import com.xbongbong.saas.enums.product.AssembleInProductEnum;
import com.xbongbong.saas.enums.product.AssembleProductEnum;
import com.xbongbong.saas.enums.product.ContractOutstockProductEnum;
import com.xbongbong.saas.enums.product.ContractProductEnum;
import com.xbongbong.saas.enums.product.InstockProductEnum;
import com.xbongbong.saas.enums.product.InventoryProductEnum;
import com.xbongbong.saas.enums.product.OpportunityProductEnum;
import com.xbongbong.saas.enums.product.OutstockProductEnum;
import com.xbongbong.saas.enums.product.ProductionInstockProductEnum;
import com.xbongbong.saas.enums.product.ProductionMaterielOutstockProductEnum;
import com.xbongbong.saas.enums.product.ProductionOrderFinishProductEnum;
import com.xbongbong.saas.enums.product.ProductionOrderMaterielProductEnum;
import com.xbongbong.saas.enums.product.PurchaseInstockProductEnum;
import com.xbongbong.saas.enums.product.PurchaseProductEnum;
import com.xbongbong.saas.enums.product.QuotationProductEnum;
import com.xbongbong.saas.enums.product.RefundInstockProductEnum;
import com.xbongbong.saas.enums.product.RefundProductEnum;
import com.xbongbong.saas.enums.product.ReturnPurchaseProductEnum;
import com.xbongbong.saas.enums.product.ReturnedMaterielInstockProductEnum;
import com.xbongbong.saas.enums.product.ReturnedPurchaseOutstockProductEnum;
import com.xbongbong.saas.enums.product.TransferProductEnum;
import lombok.Getter;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;

/**
 * @author: 汪腾伟
 * @date: Created in 2021/9/30 10:34
 * @description： BI这边统计的时候，每种子表单需要去掉的系统字段
 */
@Getter
public enum BISubProductFieldEnum {

    /**
     * 合同产品
     */
    CONTRACT_PRODUCT(BIProductReformEnum.CONTRACT_PRODUCT.getSubProductBusinessType(), BIProductReformEnum.CONTRACT_PRODUCT.getType(), Arrays.asList(ContractProductEnum.OUTSTOCK_NUM.getAttr(),
            ContractProductEnum.WAIT_OUTSTOCK_NUM.getAttr(), ContractProductEnum.RETURN_NUM.getAttr(), ContractProductEnum.STOCK.getAttr(), ContractProductEnum.OUT_OF_STOCK.getAttr(),
            ContractProductEnum.CONTRACT_STATUS.getAttr(), ContractProductEnum.SUBTOTAL.getAttr())),

    /**
     * 退货退款产品
     */
    REFUND_PRODUCT(BIProductReformEnum.REFUND_PRODUCT.getSubProductBusinessType(), BIProductReformEnum.REFUND_PRODUCT.getType(), Arrays.asList(
             RefundProductEnum.REFUND_STATUS.getAttr(), RefundProductEnum.COST.getAttr(), RefundProductEnum.SUBTOTAL.getAttr(),
             RefundProductEnum.SOURCE_DOC.getAttr(),RefundProductEnum.WAIT_INSTOCK_NUM.getAttr(),
             RefundProductEnum.EXPIRE_DATE.getAttr())),

    /**
     * 销售机会产品
     */
    SALES_OPPORTUNITY_PRODUCT(BIProductReformEnum.SALES_OPPORTUNITY_PRODUCT.getSubProductBusinessType(), BIProductReformEnum.SALES_OPPORTUNITY_PRODUCT.getType(),Arrays.asList(OpportunityProductEnum.SELL_TOTAL.getAttr())),


    /**
     * 报价单产品
     */
    QUOTATION_PRODUCT(BIProductReformEnum.QUOTATION_PRODUCT.getSubProductBusinessType(), BIProductReformEnum.QUOTATION_PRODUCT.getType(),Arrays.asList(QuotationProductEnum.SUBTOTAL.getAttr())),

    /**
     * 供应商产品
     */
    SUPPLIER_PRODUCT(BIProductReformEnum.SUPPLIER_PRODUCT.getSubProductBusinessType(), BIProductReformEnum.SUPPLIER_PRODUCT.getType(), Arrays.asList()),

    /**
     * 采购合同产品
     */
    PURCHASE_PRODUCT(BIProductReformEnum.PURCHASE_PRODUCT.getSubProductBusinessType(), BIProductReformEnum.PURCHASE_PRODUCT.getType(),
            Arrays.asList(PurchaseProductEnum.RECEIVE_STATUS.getAttr(), PurchaseProductEnum.SUBTOTAL.getAttr(), PurchaseProductEnum.WAIT_INSTOCK_NUM.getAttr())),

    /**
     * 采购退货单产品
     */
    RETURNED_PURCHASE_PRODUCT(BIProductReformEnum.RETURNED_PURCHASE_PRODUCT.getSubProductBusinessType(), BIProductReformEnum.RETURNED_PURCHASE_PRODUCT.getType(),
            Arrays.asList(ReturnPurchaseProductEnum.WAREHOUSE.getAttr(),ReturnPurchaseProductEnum.RETURN_STATUS.getAttr(), ReturnPurchaseProductEnum.SUBTOTAL.getAttr(),
                    ReturnPurchaseProductEnum.SOURCE_DOC.getAttr(), ReturnPurchaseProductEnum.WAIT_OUTSTOCK_NUM.getAttr(),ReturnPurchaseProductEnum.EXPIRE_DATE.getAttr())),

    /**
     * Bom清单成品产品
     */
    BOM_BILL_PRODUCT(BIProductReformEnum.BOM_BILL_PRODUCT.getSubProductBusinessType(), BIProductReformEnum.BOM_BILL_PRODUCT.getType(), Arrays.asList()),

    /**
     * Bom清单物料产品
     */
    BOM_BILL_MATERIEL(BIProductReformEnum.BOM_BILL_MATERIEL.getSubProductBusinessType(), BIProductReformEnum.BOM_BILL_MATERIEL.getType(), Arrays.asList()),


    /**
     * 生产单成品产品
     */
    PRODUCTION_ORDER_PRODUCT(BIProductReformEnum.PRODUCTION_ORDER_PRODUCT.getSubProductBusinessType(), BIProductReformEnum.PRODUCTION_ORDER_PRODUCT.getType(), Arrays.asList(ProductionOrderFinishProductEnum.STOCK.getAttr())),

    /**
     * 生产单物料产品
     */
    PRODUCTION_ORDER_MATERIEL(BIProductReformEnum.PRODUCTION_ORDER_MATERIEL.getSubProductBusinessType(), BIProductReformEnum.PRODUCTION_ORDER_MATERIEL.getType(), Arrays.asList(ProductionOrderMaterielProductEnum.STOCK.getAttr(),
             ProductionOrderMaterielProductEnum.WAREHOUSE.getAttr(),ProductionOrderMaterielProductEnum.WAIT_OUTSTOCK_NUM.getAttr())),

    /**
     * 装配出入库单-出库产品
     */
    ASSEMBLE_PRODUCT_OUT(BIProductReformEnum.ASSEMBLE_PRODUCT_OUT.getSubProductBusinessType(), BIProductReformEnum.ASSEMBLE_PRODUCT_OUT.getType(),
            Arrays.asList(AssembleProductEnum.STOCK.getAttr(), AssembleProductEnum.WAREHOUSE.getAttr(), AssembleProductEnum.TOTAL_COST.getAttr(),
                    AssembleProductEnum.EXPIRE_DATE.getAttr())),

    /**
     * 装配出入库单-入库产品
     */
    ASSEMBLE_PRODUCT_IN(BIProductReformEnum.ASSEMBLE_PRODUCT_IN.getSubProductBusinessType(), BIProductReformEnum.ASSEMBLE_PRODUCT_IN.getType(),
            Arrays.asList(AssembleInProductEnum.STOCK.getAttr(), AssembleInProductEnum.WAREHOUSE.getAttr(), AssembleInProductEnum.TOTAL_COST.getAttr(),
                    AssembleInProductEnum.EXPIRE_DATE.getAttr())),

    /**
     * 盘点单-盘点产品
     */
    INVENTORY_PRODUCT(BIProductReformEnum.INVENTORY_PRODUCT.getSubProductBusinessType(), BIProductReformEnum.INVENTORY_PRODUCT.getType(),
            Arrays.asList(InventoryProductEnum.INVENTORY.getAttr(), InventoryProductEnum.EXPIRE_DATE.getAttr())),

    /**
     * 调拨单-调拨产品
     */
    TRANSFER_PRODUCT(BIProductReformEnum.TRANSFER_PRODUCT.getSubProductBusinessType(), BIProductReformEnum.TRANSFER_PRODUCT.getType(),
            Arrays.asList(TransferProductEnum.STOCK.getAttr(), TransferProductEnum.TRANSFER_STATUS.getAttr(), TransferProductEnum.OUTSTOCK_NUM.getAttr(),
                    TransferProductEnum.WAIT_INSTOCK_NUM.getAttr(), TransferProductEnum.EXPIRE_DATE.getAttr())),


    /**
     * 采购入库单-入库产品
     */
    PURCHASE_INSTOCK_PRODUCT(BIProductReformEnum.PURCHASE_INSTOCK_PRODUCT.getSubProductBusinessType(), BIProductReformEnum.PURCHASE_INSTOCK_PRODUCT.getType(),
            Arrays.asList(PurchaseInstockProductEnum.STOCK.getAttr(), PurchaseInstockProductEnum.WAREHOUSE.getAttr(), PurchaseInstockProductEnum.TOTAL_COST.getAttr(),
                    PurchaseInstockProductEnum.EXPIRE_DATE.getAttr())),

    /**
     * 销售退货入库单-入库产品
     */
    REFUND_INSTOCK_PRODUCT(BIProductReformEnum.REFUND_INSTOCK_PRODUCT.getSubProductBusinessType(), BIProductReformEnum.REFUND_INSTOCK_PRODUCT.getType(),
            Arrays.asList(RefundInstockProductEnum.STOCK.getAttr(), RefundInstockProductEnum.WAREHOUSE.getAttr(),  RefundInstockProductEnum.SUBTOTAL.getAttr(),
                    RefundInstockProductEnum.TOTAL_COST.getAttr(), RefundInstockProductEnum.EXPIRE_DATE.getAttr())),

    /**
     * 其他入库单 - 盘盈入库、调拨入库、装配入库也归属该类-入库产品
     */
    OTHER_INSTOCK_PRODUCT(BIProductReformEnum.OTHER_INSTOCK_PRODUCT.getSubProductBusinessType(), BIProductReformEnum.OTHER_INSTOCK_PRODUCT.getType(),
            Arrays.asList(InstockProductEnum.STOCK.getAttr(), InstockProductEnum.WAREHOUSE.getAttr(), InstockProductEnum.TOTAL_COST.getAttr(),
                    InstockProductEnum.EXPIRE_DATE.getAttr())),

    /**
     * 生产入库单 - 入库产品
     */
    PRODUCTION_INSTOCK_PRODUCT(BIProductReformEnum.PRODUCTION_INSTOCK_PRODUCT.getSubProductBusinessType(), BIProductReformEnum.PRODUCTION_INSTOCK_PRODUCT.getType(), Arrays.asList(ProductionInstockProductEnum.STOCK.getAttr(),
            ProductionInstockProductEnum.WAREHOUSE.getAttr(), ProductionInstockProductEnum.TOTAL_COST.getAttr(), ProductionInstockProductEnum.EXPIRE_DATE.getAttr())),

    /**
     * 生产退料单- 入库产品
     */
    RETURNED_MATERIEL_INSTOCK_PRODUCT(BIProductReformEnum.RETURNED_MATERIEL_INSTOCK_PRODUCT.getSubProductBusinessType(), BIProductReformEnum.RETURNED_MATERIEL_INSTOCK_PRODUCT.getType(), Arrays.asList(ReturnedMaterielInstockProductEnum.STOCK.getAttr(),
            ReturnedMaterielInstockProductEnum.WAREHOUSE.getAttr(), ReturnedMaterielInstockProductEnum.TOTAL_COST.getAttr(), ReturnedMaterielInstockProductEnum.SOURCE_DOC.getAttr(),
            ReturnedMaterielInstockProductEnum.EXPIRE_DATE.getAttr())),

    /**
     * 销售出库单- 出库产品
     */
    CONTRACT_OUTSTOCK_PRODUCT(BIProductReformEnum.CONTRACT_OUTSTOCK_PRODUCT.getSubProductBusinessType(), BIProductReformEnum.CONTRACT_OUTSTOCK_PRODUCT.getType(), Arrays.asList(ContractOutstockProductEnum.STOCK.getAttr(),
            ContractOutstockProductEnum.WAREHOUSE.getAttr(), ContractOutstockProductEnum.PRICE.getAttr(), ContractOutstockProductEnum.SUBTOTAL.getAttr(),
            ContractOutstockProductEnum.TOTAL_COST.getAttr(), ContractOutstockProductEnum.EXPIRE_DATE.getAttr())),

    /**
     * 采购退货出库单- 出库产品
     */
    RETURNED_PURCHASE_OUTSTOCK_PRODUCT(BIProductReformEnum.RETURNED_PURCHASE_OUTSTOCK_PRODUCT.getSubProductBusinessType(), BIProductReformEnum.RETURNED_PURCHASE_OUTSTOCK_PRODUCT.getType(), Arrays.asList(ReturnedPurchaseOutstockProductEnum.STOCK.getAttr(),
            ReturnedPurchaseOutstockProductEnum.WAREHOUSE.getAttr(), ReturnedPurchaseOutstockProductEnum.TOTAL_COST.getAttr(), ReturnedPurchaseOutstockProductEnum.EXPIRE_DATE.getAttr())),

    /**
     * 其他出库单 - 盘亏出库、调拨出库、装配出库也归属该类- 出库产品
     */
    OTHER_OUTSTOCK_PRODUCT(BIProductReformEnum.OTHER_OUTSTOCK_PRODUCT.getSubProductBusinessType(), BIProductReformEnum.OTHER_OUTSTOCK_PRODUCT.getType(), Arrays.asList(OutstockProductEnum.STOCK.getAttr(),
            OutstockProductEnum.WAREHOUSE.getAttr(), OutstockProductEnum.TOTAL_COST.getAttr(), OutstockProductEnum.EXPIRE_DATE.getAttr())),

    /**
     * 生产领料单 - 出库产品
     */
    PRODUCTION_MATERIEL_OUTSTOCK_PRODUCT(BIProductReformEnum.PRODUCTION_MATERIEL_OUTSTOCK_PRODUCT.getSubProductBusinessType(), BIProductReformEnum.PRODUCTION_MATERIEL_OUTSTOCK_PRODUCT.getType(), Arrays.asList(ProductionMaterielOutstockProductEnum.STOCK.getAttr(),
            ProductionMaterielOutstockProductEnum.WAREHOUSE.getAttr(), ProductionMaterielOutstockProductEnum.TOTAL_COST.getAttr(),
            ProductionMaterielOutstockProductEnum.EXPIRE_DATE.getAttr())),

    ;

    /**
     * 产品子表单业务类型
     */
    private Integer subProductBusinessType;

    /**
     * 增加一个字段用于区分产品，比如bom单中有成品产品和物料产品，得有标识去区分，
     * 值最好要用各自产品表中的type字段，比如tb_saas_bom_product中有type去区分成品和物料
     */
    private Integer type;

    /**
     * 需要过滤的字段集合（如计算字段或其他业务端未入库的逻辑字段等无法打到数仓的字段需要剔除）
     */
    private List<String> fieldList;

    BISubProductFieldEnum(Integer subProductBusinessType, Integer type, List<String> fieldList) {
        this.subProductBusinessType = subProductBusinessType;
        this.type = type;
        this.fieldList = fieldList;
    }

    /**
     * 通过产品子表单的业务类型获取表单解释
     *
     * @return
     */
    public static List<String> getFieldListBySubProductBus(Integer subProductBusinessType, Integer type) {
        for (BISubProductFieldEnum biSubProductFieldEnum : BISubProductFieldEnum.values()) {
            if (Objects.equals(subProductBusinessType, biSubProductFieldEnum.getSubProductBusinessType()) && Objects.equals(type, biSubProductFieldEnum.getType())) {
                return biSubProductFieldEnum.getFieldList();
            }
        }
        return null;
    }
}
